package com.customization.webservice.flowtrigger.impl;


import com.alibaba.druid.sql.ast.expr.SQLAllExpr;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.customization.commons.Console;
import com.customization.webservice.flowtrigger.Output;

import com.engine.workflow.biz.freeNode.FreeNodeBiz;
import com.engine.workflow.biz.publicApi.RequestOperateBiz;
import com.engine.workflow.entity.publicApi.PAResponseEntity;
import com.engine.workflow.entity.publicApi.ReqOperateRequestEntity;
import com.engine.workflow.publicApi.WorkflowRequestOperatePA;
import com.engine.workflow.publicApi.impl.WorkflowRequestOperatePAImpl;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.workflow.webservices.WorkflowRequestInfo;
import weaver.workflow.webservices.WorkflowRequestTableField;
import weaver.workflow.webservices.WorkflowServiceImpl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UpdateCBSPayInfo {

    JSONObject dataInput=new  JSONObject();


    static String REQUESTID="";
    String errormsg="";
    public Output execute (String input) throws Exception {
         
             JSONArray outputArray=new JSONArray();
             Output output = new Output();

            JSONArray jsonArray=JSONArray.parseArray(input);
            Console.log("UpdateCBSPayInfo input params：" + input);
            JSONObject res=new JSONObject();

            String workflowNumber="";
            String requestid="-1";
            String linenr="";
            String boenr="";
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject data=jsonArray.getJSONObject(i);
                this.dataInput=data;


                  workflowNumber="";
                  requestid="";
                  linenr="";
                  boenr="";

                try {
                    workflowNumber =  Util.null2String(data.getString("workflownumber"));
                    if(workflowNumber.equals("")){
                        errormsg="workflowNumber";
                        break;
                    }
                    requestid = Util.null2String(data.getString("requestid"));

                    if(requestid.equals("")){
                        errormsg="requestid";
                        break;
                    }

                    String payDate = Util.null2String(data.getString("paydate"));
                    if(payDate.equals("")){
                        errormsg="payDate";
                        break;
                    }
                    String payStatus =  Util.null2String(data.getString("paystatus"));

                    if(payStatus.equals("")){
                        errormsg="payStatus";
                        break;
                    }

                    String payAmount = Util.null2String(data.getString("payamount"));
                    if(payAmount.equals("")){
                        errormsg="payAmount";
                        break;
                    }


                    String payVoucher = Util.null2String(data.getString("payvoucher"));
                    String pay_errorInfo = Util.null2String(data.getString("payerrorinfo"));
                    String pay_ebr_no = Util.null2String(data.getString("payebrno"));
                    String pay_desc = Util.null2String(data.getString("paydesc"));
                    String cleardocno= Util.null2String(data.getString("cleardocno"));
                    String cleardocmsg= Util.null2String(data.getString("cleardocmsg"));
                    linenr = Util.null2String(data.getString("linenr"));
                    boenr = Util.null2String(data.getString("boenr"));

                    RecordSet rs = new RecordSet();

                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                    Date date = new Date(System.currentTimeMillis());

                    String MODEDATACREATEDATE = formatter.format(date);
                    formatter = new SimpleDateFormat("HH:mm:ss");
                    String MODEDATACREATETIME = formatter.format(date);

                    //本地存储SAP的数据
                    String insertsql = "insert into uf_cbs_pay (MODEDATACREATEDATE,MODEDATACREATETIME," +
                            "boenr,workflowNumber,payDate,payStatus," +
                            "wfid,payAmount,payVoucher," +
                            "pay_ebr_no,pay_desc,pay_errorInfo,linenr,cleardocno,cleardocmsg) " +
                            "values ('"+MODEDATACREATEDATE+"','"+MODEDATACREATETIME+"','"+boenr+"','"
                            + workflowNumber + "','" + payDate + "','" + payStatus + "','"
                            + requestid + "','" + payAmount + "','" + payVoucher + "','"
                            + pay_ebr_no + "','" + pay_desc + "','" + pay_errorInfo + "','"+linenr+"','"+cleardocno+"','"+cleardocmsg+"')";
                    Console.log(requestid+"insertsql:" + insertsql);
                    boolean b=rs.execute(insertsql);

                    if(b){
                        try {
                            if(data.containsKey("salarylist")){
                                JSONArray salarylist = data.getJSONArray("salarylist");
                                if (salarylist.size() > 0) {
                                    rs.execute("select max(id) as id from uf_cbs_pay where wfid='"+requestid+"'");
                                    rs.first();
                                    String mainid = rs.getString("id");
                                    for (int k = 0; k < salarylist.size(); k++) {
                                        JSONObject json=(JSONObject)salarylist.get(k);
                                        String revacc=json.getString("revacc");
                                        String revbnk=json.getString("revbnk");
                                        String wagmny=json.getString("wagmny");
                                        String pernr=json.getString("pernr");
                                        String revnam=json.getString("revnam");
                                        String remark=json.getString("remark");
                                        String status=json.getString("status");
                                        String insertDt="insert into uf_cbs_pay_dt1 (mainid,revacc,revbnk,wagmny,pernr,revnam,remark,status) values('"+mainid+"','"+revacc+"','"+revbnk+"','"+wagmny+"','"+pernr+"','"+revnam+"','"+remark+"','"+status+"')";
                                        Console.log(requestid+"insertDt:"+insertDt);
                                        boolean a= rs.execute(insertDt);
                                    }
                                }
                            }
                            REQUESTID=requestid;

                            if(linenr.equals("01")) {
                                new Thread((new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            Console.log("CBS异步提交流程"+REQUESTID);
                                            submitWorkflow(REQUESTID);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                })).start();
                            }



                        }catch (Exception e){
                            res.put("message", e.toString());
                            res.put("status", false);
                            res.put("workflownumber", workflowNumber);
                            res.put("requestid", requestid);
                            output.setMessage(res.toString());
                            return output;

                        }
                    }else{
                        res.put("message", "内部程序异常");
                        res.put("status", false);
                        res.put("workflownumber", workflowNumber);
                        res.put("requestid", requestid);
                        output.setMessage(res.toString());
                        return output;
                        
                    }


                }catch (Exception e){
                    res.put("message", e.toString());
                    res.put("status", false);
                    res.put("workflownumber", workflowNumber);
                    res.put("requestid", requestid);
                    output.setMessage(res.toString());
                    return output;
                }

            }
            if(!errormsg.equals("")){
                res.put("message",errormsg+"不能为空");
                res.put("status", false);
                res.put("workflownumber", workflowNumber);
                res.put("requestid", requestid);
                output.setMessage(res.toString());
                return output;

            }else {
                res.put("message", "保存成功");
                res.put("status", true);
                res.put("workflownumber", workflowNumber);
                res.put("requestid", requestid);
            }

        output.setMessage(res.toString());
        return output;
    }



    public void submitWorkflow(String requestidTemp){


        RecordSet rs = new RecordSet();
        RecordSet rs3 = new RecordSet();

        boolean isexitorder = false;


        String sqlwhere=" and (status is null or status not in ('1','-1','2','3')) ";
        if(!requestidTemp.equals("")){
           sqlwhere=" and wfid='"+requestidTemp+"'";
        }

        //依次处理中间表没有成功的数据;
        // String sql=" select *  from uf_cbs_pay where （status is null or status not in ('1','-1') )   and LINENR='01' "+sqlwhere  +" order by status desc,id desc";
        String sql=" select  * from ( select t1.*,row_number() over(partition by wfid order by id desc) rn  from (select *  from uf_cbs_pay where  LINENR='01' "+sqlwhere+" order by   status desc ,id    desc)t1 ) t where rn=1 order by status desc,MODEDATACREATEDATE asc,MODEDATACREATETIME asc";
        Console.log("查询即将处理成功的数据："+sql);
        rs3.execute(sql);
        String mainid="0";
        String dataid="0";
        int  count=1;
        while (rs3.next()) {

            String gllczt="";//标记流程状态  0 未归档  1已归档

            count++;
            if(count>10){
                break;
            }

            String workflowNumber = Util.null2String(rs3.getString("workflowNumber"));
            String payDate = Util.null2String(rs3.getString("payDate"));
            String payVoucher = Util.null2String(rs3.getString("payVoucher"));
            String payStatus = Util.null2String(rs3.getString("payStatus"));
            String payAmount = Util.null2String(rs3.getString("payAmount"));
            int requestid = Util.getIntValue(Util.null2String(rs3.getString("wfid")));
            String pay_errorInfo = Util.null2String(rs3.getString("pay_errorInfo"));
            String pay_ebr_no = Util.null2String(rs3.getString("pay_ebr_no"));
            String pay_desc= Util.null2String(rs3.getString("pay_desc"));
            String cleardocno= Util.null2String(rs3.getString("cleardocno"));
            String cleardocmsg= Util.null2String(rs3.getString("cleardocmsg"));
            String boenr= Util.null2String(rs3.getString("boenr"));
            mainid= Util.null2String(rs3.getString("id"));
            dataid=mainid;
            System.out.println("requestid:"+requestid+";workflowNumber="+workflowNumber);
            if(payStatus.equals("支付成功")){
                pay_errorInfo="";
            }


            //表示清账失败
            if(cleardocmsg.equals("")){
                releaseClearNo(requestid);
            }


            if(workflowNumber.equals("")&&requestid==0){
                String updateStatus = " update uf_cbs_pay set status='-1' where id='"+dataid + "'";
                rs.execute(updateStatus);
                continue;
            }

            int wfid=0;
            rs.execute("select * from workflow_requestbase where requestmark ='" + workflowNumber + "' and requestid='" + requestid + "'");

            String CURRENTNODETYPE="";
            if (rs.next()) {
                isexitorder = true;

                wfid = rs.getInt("workflowid");
                CURRENTNODETYPE=  rs.getString("CURRENTNODETYPE");
            }
            //获取流程上面的节点操作者ID
            rs.execute("select RECEIVEDPERSONIDS from  workflow_requestlog where requestid='" + requestid + "' order by operatedate||' '||OPERATETIME desc");
            int userid = 0;
             if (rs.next()) {
                userid = rs.getInt("RECEIVEDPERSONIDS");
            }

            System.out.println("userid:  " + userid);
            WorkflowServiceImpl workflowService = new WorkflowServiceImpl();
            String  [] conditions={"t1.requestid="+requestid};
            WorkflowRequestInfo [] res= workflowService.getToDoWorkflowRequestList(1,10,100,13513,conditions);


            //2021/2/26 10:14 lth     判断当前流程是不是在支付节点，如果是就去调用接口处理流程
            if(res.length==1){
                isexitorder = true;
                Console.log(requestid+"是待办,开始调用接口提交流程");
            }else{
                isexitorder = false;
                WorkflowRequestInfo [] processedRes = workflowService.getProcessedWorkflowRequestList(1,10,100,13513,conditions);
                if(processedRes.length==1){//如果流程已经归档直接更新数据为已处理
                    String updateStatus = "update uf_cbs_pay set status='3' where id='"+dataid + "'";
                    rs.execute(updateStatus);
                    Console.log(requestid+"已归档,并且操作-updateStatus:" + updateStatus);


                    //2021/2/26 17:57 lth    流程调用接口提交之后 更新流转状态到发票信息表里面 Start
                    // gllczt  0 未归档  1已归档
                    updateStatus = "update uf_fp set gllczt='"+gllczt+"' where id='"+dataid+ "'";
                    rs.execute(updateStatus);
                    //2021/2/26 17:57 lth    流程调用接口提交之后 更新流转状态到发票信息表里面 END
                }else{
                    String updateStatus = "update uf_cbs_pay set status='2' where id='"+dataid + "'";
                    rs.execute(updateStatus);
                    Console.log(requestid+"未归档,不是待办-updateStatus:" + updateStatus);

                    //2021/2/26 17:57 lth    流程调用接口提交之后 更新流转状态到发票信息表里面 Start
                    // gllczt  0 未归档  1已归档
                    updateStatus = "update uf_fp set gllczt='"+gllczt+"' where id='"+dataid+ "'";
                    rs.execute(updateStatus);
                    //2021/2/26 17:57 lth    流程调用接口提交之后 更新流转状态到发票信息表里面 END

                }
            }


            rs.execute("select formid from workflow_base where id ='" + wfid + "' ");
            rs.first();
            int formid = rs.getInt("formid");
            System.out.println("formid："+formid);

            if (isexitorder) {


                String zfrq = "";
                String zfsj = "";
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
                //必须捕获异常
                try {
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    Date date =null;
                    if(!payDate.equals("")) {
                        date= simpleDateFormat.parse(payDate);
                    }else{
                        date=new Date();
                        Console.log(requestid+"单据"+requestid+"没有传递支付日期");
                    }
                    zfrq = dateFormat.format(date);

                    dateFormat = new SimpleDateFormat("HH:mm");
                    zfsj = dateFormat.format(new Date());

                } catch (ParseException px) {
                    px.printStackTrace();
                }


                String filedStr = " payDate='"+payDate+"',"+
                        "payVoucher='"+payVoucher+"'," +
                        "payStatus='"+payStatus+"'," +
                        "pay_errorInfo='"+pay_errorInfo+"'," +
                        "pay_ebr_no='"+pay_ebr_no+"'," +
                        "pay_desc='"+pay_desc+"'," +
                        "payAmount='"+payAmount+"'";

                String updatesql = "update formtable_main_" + Math.abs(formid) + " set " + filedStr + " where requestid='" + requestid + "' ";
                Console.log(requestid+"回写支付信息:updatesql:" + updatesql);
                rs.execute(updatesql);

                try {
                    filedStr = " qzpz='" + cleardocno + "' ";
                    updatesql = "update formtable_main_" + Math.abs(formid) + " set " + filedStr + " where requestid='" + requestid + "' ";
                    Console.log(requestid+"更新清账凭证:updatesql:" + updatesql);
                    rs.execute(updatesql);
                }catch (Exception e){
                    e.printStackTrace();
                    Console.log(requestid+"清账凭证更新报错:"+e.toString());
                }

                try {
                    filedStr = " pjh='" + boenr + "' ";
                    updatesql = "update formtable_main_" + Math.abs(formid) + " set " + filedStr + " where requestid='" + requestid + "' ";
                    Console.log(requestid+"更新票据号:updatesql:" + updatesql);
                    rs.execute(updatesql);
                }catch (Exception e){
                    e.printStackTrace();
                    Console.log(requestid+"票据号更新报错:"+e.toString());
                }

                try {

                    String reject_pay_errorInfo =Util.null2String(rs.getPropValue("angel_fna","cbskeywords"));
                    if(reject_pay_errorInfo.equals("")){
                         reject_pay_errorInfo="支付信息有误,确认支付失败,银行退票";
                    }
                    String addr=pay_errorInfo;

                    if(addr.contains("|")){
                        addr=addr.split("\\|")[0];
                    }


                    {
                        if (payStatus.equals("支付失败") && reject_pay_errorInfo.contains(addr)) {  //流程提交到是否重新提交节点
                            filedStr = " sfcxfqfk='0'   ";
                            gllczt="0";//标记流程状态  0 未归档  1已归档
                        } else {
                            filedStr = " sfcxfqfk='1'   ";
                            gllczt="1";//标记流程状态  0 未归档  1已归档
                        }
                        updatesql = "update formtable_main_" + Math.abs(formid) + " set " + filedStr + " where requestid='" + requestid + "' ";
                        Console.log(requestid+"更新是否可以重新提交:updatesql:" + updatesql);
                        rs.execute(updatesql);
                    }

                }catch (Exception e){
                    e.printStackTrace();
                    Console.log(requestid+"更新是否可以重新提交报错:"+e.toString());
                }


                try {

                    /*
                    String remark = payStatus+"，流程自动提交";
                    String type = "submit";//submit 提交 subnoback提交不需返回  subback提交需要返回 reject

                    WorkflowRequestInfo responseInfo = workflowService.getWorkflowRequest(requestid, userid, requestid);
                    Console.log(requestid+"开始调用接口提交流程");
                    String resp = workflowService.submitWorkflowRequest(responseInfo, requestid, userid, type, remark);
                    Console.log(requestid+"调用接口提交流程返回"+resp);
                    if (resp.equals("success")) {
                        String updateStatus = "update uf_cbs_pay set status='1' where id='"+dataid + "'";
                        Console.log(requestid+"updateStatus:" + updateStatus);
                        rs.execute(updateStatus);
                        Console.log(requestid+"成功流转到下一节点:" + updatesql);

                        //2021/2/26 10:57 lth    流程调用接口提交之后 更新流转状态到发票信息表里面 Start

                        // gllczt  0 未归档  1已归档
                        updateStatus = "update uf_fp set gllczt='"+gllczt+"' where id='"+dataid+ "'";
                        rs.execute(updateStatus);
                        //2021/2/26 10:57 lth    流程调用接口提交之后 更新流转状态到发票信息表里面 END


                    }else{
                        Console.log(requestid+"resp:"+resp);
                        String updateStatus = "update uf_cbs_pay set status=nvl(status,0)-2  where id='"+dataid + "'";
                        Console.log(requestid+"updateStatus:" + updateStatus);
                        rs.execute(updateStatus);
                    }

                     */

                    WorkflowRequestOperatePA workflowRequestOperatePA = new WorkflowRequestOperatePAImpl();;

                    PAResponseEntity paResponseEntity = workflowRequestOperatePA.submitRequest(new User(13513), this.request2Entity(requestid, payStatus+"，流程自动提交"));
                    JSONObject  result=JSONObject.parseObject(JSONObject.toJSONString(paResponseEntity));
                    String code= Util.null2String(result.get("code"));
                    if(!code.equals("SUCCESS")){

                        String errorinfo=result.toString();
                        Console.log(requestid+"resp:"+errorinfo);
                        String updateStatus = "update uf_cbs_pay set status=nvl(status,0)-2  where id='"+dataid + "'";
                        Console.log(requestid+"updateStatus:" + updateStatus);
                        rs.execute(updateStatus);

                        if(errorinfo.indexOf("'")>-1) {
                            errorinfo = errorinfo.replace("'", "''");
                            errorinfo = errorinfo.replace("insert", "in-sert");
                            errorinfo = errorinfo.replace("update", "up-date");
                            errorinfo = errorinfo.replace("delete", "de-lete");
                        }
                        try{
                            rs.execute("update uf_cbs_pay  set lastErrorInfo='"+errorinfo+"' where id='"+dataid + "'");
                        }catch (Exception e){

                        }



                    }else{
                        String updateStatus = "update uf_cbs_pay set status='1',lastErrorInfo='' where id='"+dataid + "'";
                        Console.log(requestid+"updateStatus:" + updateStatus);
                        rs.execute(updateStatus);
                        Console.log(requestid+"成功流转到下一节点:" + updatesql);

                        //2021/2/26 10:57 lth    流程调用接口提交之后 更新流转状态到发票信息表里面 Start

                        // gllczt  0 未归档  1已归档
                        updateStatus = "update uf_fp set gllczt='"+gllczt+"' where id='"+dataid+ "'";
                        rs.execute(updateStatus);
                        //2021/2/26 10:57 lth    流程调用接口提交之后 更新流转状态到发票信息表里面 END

                    }


                } catch (Exception e) {
                    e.printStackTrace();
                    Console.log(requestid+"提交流程报错:"+e.toString());
                }

                /*
                if (payStatus.equals("支付成功")) {//支付成功
                    try {
                        String remark = "CBS支付成功，流程自动提交";
                        String type = "submit";//submit 提交 subnoback提交不需返回  subback提交需要返回 reject
                        WorkflowServiceImpl workflowService = new WorkflowServiceImpl();
                        WorkflowRequestInfo responseInfo = workflowService.getWorkflowRequest(requestid, userid, requestid);
                        String resp = workflowService.submitWorkflowRequest(responseInfo, requestid, userid, type, remark);
                        if (resp.equals("success")) {
                            String updateStatus = "update uf_cbs_pay set status='1' where requestid='" + requestid + "'";
                            rs.execute(updateStatus);
                            Console.log(("成功流转到下一节点:" + updatesql);
                        }
                    } catch (Exception e) {

                    }
                } else {//未支付成功流程退回到第一步，需要设置支付节点的退回出口

                    try {
                        String remark = "CBS支付失败,";
                        String type = "reject";//submit 提交 subnoback提交不需返回  subback提交需要返回 reject
                        WorkflowServiceImpl workflowService = new WorkflowServiceImpl();
                        WorkflowRequestInfo responseInfo = workflowService.getWorkflowRequest(requestid, userid, requestid);

                        String resp = workflowService.submitWorkflowRequest(responseInfo, requestid, userid, type, remark);
                        if (resp.equals("success")) {
                            String updateStatus = "update uf_cbs_pay set status='2' where requestid='" + requestid + "'";
                            rs.execute(updateStatus);
                            Console.log(("成功流转到下一节点:" + updatesql);
                        }
                    } catch (Exception e) {

                    }
                    Console.log(("未支付成功 更新流程中支付状态成功！");
                }
                */



            } else {

            }
        }
    }

    public  String checkNeedInput(String key){
        String value= Util.null2String(this.dataInput.getString(key));
        if(value.equals("")) {
            throw new RuntimeException("字段"+key+"的值不能为空");
        }
        return value;
    }

    public Output demo () throws Exception {
        Output output = new Output();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("workflowNumber","");
        jsonObject.put("requestid","");
        jsonObject.put("payDate","");
        jsonObject.put("payStatus","");
        jsonObject.put("payAmount","");
        jsonObject.put("payVoucher","");
        jsonObject.put("pay_errorInfo","");
        jsonObject.put("pay_ebr_no","");
        jsonObject.put("pay_desc","");
        output.setMessage(jsonObject.toString());
        return output;
    }


    public void releaseClearNo(int  requestid){

        /*  需要清账的流程
            FI201 formtable_main_639_dt11
            FI203 formtable_main_620_dt6
            FI205 formtable_main_634_dt6
       */
        String sql =" select  * from(" +
                    " select dt.pzbh,dt.hjnd,dt.gsdm,wr.currentnodetype,wr.requestid from formtable_main_639 fm,formtable_main_639_dt11 dt,workflow_requestbase wr where dt.mainid=fm.id  and wr.requestid=fm.requestid " +
                    " union all " +
                    " select dt.pzbh,dt.hjnd,dt.gsdm,wr.currentnodetype,wr.requestid from formtable_main_620 fm,formtable_main_620_dt6 dt,workflow_requestbase wr where dt.mainid=fm.id  and wr.requestid=fm.requestid " +
                    " union all " +
                    " select dt.pzbh,dt.kjnd,dt.gsdm,wr.currentnodetype,wr.requestid from formtable_main_634 fm,formtable_main_634_dt6 dt,workflow_requestbase wr where dt.mainid=fm.id  and wr.requestid=fm.requestid "+
                    "  ) t where t.requestid='"+requestid+"'";

        RecordSet  rst=new RecordSet();
        RecordSet  rs=new RecordSet();
        rst.executeQuery(sql);
        while (rst.next()){
            String pzbh=rst.getString("pzbh");//凭证号
            String kjnd=rst.getString("hjnd");//会计年度
            String gsdm=rst.getString("gsdm");//公司代码
            String upsql="update  uf_fnaVoucher set zt='1' where pzh='"+pzbh+"'  and nf='"+kjnd+"'  and gsdm='"+gsdm+"'";
            boolean res=rs.execute(upsql);
            if(!res) Console.log(requestid+"释放清账的数据"+upsql);
        }
    }

    public static void main(String[] args) {
        String addr="ssdd|122";
        if(addr.contains("|")){
            addr=addr.split("\\|")[0];
        }
        System.out.println(addr);
    }


     private HashMap params =new HashMap();

    public ReqOperateRequestEntity request2Entity(int requstid,String remark) {
        ReqOperateRequestEntity var1 = new ReqOperateRequestEntity();

        try {
            int var3 = Util.getIntValue(""+requstid);
            String var4 = Util.null2String(this.params.get("requestName"));
            int var5 = Util.getIntValue(Util.null2String(this.params.get("userId")));
            int var6 = Util.getIntValue(Util.null2String(this.params.get("forwardFlag")));
            String var7 = Util.null2String(this.params.get("forwardResourceIds"));
            String var8 = Util.null2String(this.params.get("mainData"));
            if (!"".equals(var8)) {
                try {
                    List var9 = JSONObject.parseArray(var8, WorkflowRequestTableField.class);
                    var1.setMainData(var9);
                } catch (Exception var16) {
                    var16.printStackTrace();
                }
            }

            String var18 = Util.null2String(this.params.get("detailData"));
            if (!"".equals(var18)) {
                try {
                    //     List var10 = JSONObject.parseArray(var18, WorkflowDetailTableInfoEntity.class);
                    //   var1.setDetailData(var10);
                } catch (Exception var15) {
                    var15.printStackTrace();
                }
            }

            String var19 = Util.null2String(remark);
            String var11 = Util.null2String(this.params.get("requestLevel"));
            String var12 = Util.null2String(this.params.get("otherParams"));
            if (!"".equals(var12)) {
                try {
                    Map var13 = (Map)JSONObject.parseObject(var12, Map.class);
                    var1.setOtherParams(var13);
                } catch (Exception var14) {
                    var14.printStackTrace();
                }
            }
            Console.log("OtherParams:"+var1.getOtherParams().toString());

            var1.setWorkflowId(-1);
            var1.setRequestId(var3);
            var1.setRequestName(var4);
            var1.setUserId(var5);
            var1.setRemark(var19);
            var1.setRequestLevel(var11);
            var1.setForwardFlag(var6);
            var1.setForwardResourceIds(var7);
            var1.setClientIp("127.0.0.1");
            int var20 = Util.getIntValue(Util.null2String(this.params.get("submitNodeId")));
            if (var20 > 0 || FreeNodeBiz.isFreeNode(var20)) {
                var1.setSubmitNodeId(var20);
                var1.setEnableIntervenor("1".equals(Util.null2s(Util.null2String(this.params.get("enableIntervenor")), "1")));
                var1.setSignType(Util.getIntValue(Util.null2String(this.params.get("SignType")), 0));
                var1.setIntervenorid(Util.null2String(this.params.get("Intervenorid")));
            }
        } catch (Exception var17) {
            var17.printStackTrace();

        }

        return var1;
    }





}
